#ifndef __CONVERT_H__
#define __CONVERT_H__

#include "types.h"
#include "dynamic_array.h"
#include "dynamic_string.h"

#include <time.h>

typedef enum ColumnType {
    COL_TYPE_STR = 0,
    COL_TYPE_F32,
    COL_TYPE_F64,
    COL_TYPE_DATE,
    COL_TYPE_CATEGORICAL,
    COL_TYPE_LEN,
} ColumnType;

// satisfies String_Builder
typedef struct StrColumn {
    String_Builder *items;
    u64 length;
    u64 capacity;
    ColumnType type;
} StrColumn;

// satisfies dyn_array structure
typedef struct F32Column {
    f32 *items;
    u64 length;
    u64 capacity;
    ColumnType type;
} F32Column;

// satisfies dyn_array structure
typedef struct F64Column {
    f64 *items;
    u64 length;
    u64 capacity;
    ColumnType type;
} F64Column;

typedef struct HashArray {
    u64 *items;
    u64 length;
    u64 capacity;
} HashArray;

typedef struct HashList {
    u64 *items;
    u64 length;
    u64 capacity;
    String_Builder_Array *sba;
    HashArray *ha;
} HashList;

typedef struct CategoricalColumn {
    u64 *items;
    u64 length;
    u64 capacity;
    HashList *hl;
    ColumnType type;
} CategoricalColumn;

typedef struct tm Date;

typedef struct DateColumn {
    Date *items;
    u64 length;
    u64 capacity;
    String_Builder format;
    String_Builder display;
    ColumnType type;
} DateColumn;

void sba_to_f32(String_Builder_Array *sba, F32Column *col, u64 header_size);
void sba_to_f64(String_Builder_Array *sba, F64Column *col, u64 header_size);
void sba_to_str(String_Builder_Array *sba, StrColumn *col, u64 header_size);
void sba_to_categorical(String_Builder_Array *sba, CategoricalColumn *col, u64 header_size);
void sba_to_date(String_Builder_Array *sba, DateColumn *col, u64 header_size);
// i32 hash_list_compare(const void *a, const void *b);
u64 hash_sb(String_Builder *sb);
void hash_sba(String_Builder_Array *sba_full, String_Builder_Array *sba_new, HashArray *ha);
void init_hash_list(HashList *hl, String_Builder_Array *sba_full, String_Builder_Array *sba_new, HashArray *ha);
void print_col_f32(F32Column *col);
void print_col_f64(F64Column *col);
void print_col_str(StrColumn *col);
void print_col_cat(CategoricalColumn *col);
void print_col_date(DateColumn *col);
void free_categorical_column(CategoricalColumn *col);
void free_date_column(DateColumn *col);
void free_f32_column(F32Column *col);
void free_f64_column(F64Column *col);
void free_string_column(StrColumn *col);
void free_hash_list(HashList hl);

#endif // __CONVERT_H__
